package com.chao.product.message;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@RabbitListener(queues = "topic_queue_1")
public class TopicMsg1 {

    @RabbitHandler
    public void topicGetMsg(String content, Message message, Channel channel) throws IOException {
        try{
            int i = 1/0;
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        }catch (Exception e){
            channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,false);
        }
        System.out.println(message.getMessageProperties().getReceivedRoutingKey());
        System.out.println("consumer-1:" + content);
    }
}
